1139 A Even Substrings

cf传送门:Even Substrings
vj传送门:Even Substrings

题目描述

You are given a string s=s1s2…sn of length n, which only contains digits 1, 2, ..., 9.

A substring s[l…r] of s is a string slsl+1sl+2…sr. A substring s[l…r] of s is called even if the number represented by it is even.

Find the number of even substrings of s. Note, that even if some substrings are equal as strings, but have different l and r, they are counted as different substrings.

Input
The first line contains an integer n (1≤n≤65000) — the length of the string s.

The second line contains a string s of length n. The string s consists only of digits 1, 2, ..., 9.

Output
Print the number of even substrings of s.

Examples
Input
4
1234
Output
6
Input
4
2244
Output
10
Note
In the first example, the [l,r] pairs corresponding to even substrings are:

s[1…2]
s[2…2]
s[1…4]
s[2…4]
s[3…4]
s[4…4]
In the second example, all 10 substrings of s are even substrings. Note, that while substrings s[1…1] and s[2…2] both define the substring "2", they are still counted as different substrings.

题意分析

这道题说实话直接看我真的看不懂,然后我借助翻译,,,发现还是看不懂。经过一段时间的挣扎和猜题意终于是看懂了这道题。
这道题就是输入一个字符串,让我们判断它的子串中偶数的个数,偶数指的就是把子串看成是整形的偶数。字符串的长度最大时65000,所以两重for是肯定不能用的,这时候就显现出了思维的重要性。如果这个字符串表示的数是偶数,那么它的最后一位一定是2或2的倍数。根据这一点就可以判断了。具体看代码

代码实现

#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    string s,l;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if((s[i]-'0')%2==0)
            ans+=(i+1);
    }
    cout<<ans<<endl;
    return 0;
}